import './bootstrap';

const THEME_KEY = 'theme';


//  主题切换
let elements = document.querySelectorAll('.change-theme');
elements.forEach(function (element) {
    element.addEventListener('click', function () {
        let d = document.getElementsByTagName('html')[0].getAttribute('class');
        localStorage.setItem(THEME_KEY, d === 'dark' ? 'light' : 'dark');
        toggleTheme(d  ==='dark');
    })
})

var toggleTheme = function (flag) {
    if (flag) {
        setTheme('light');
    } else {
        setTheme('dark')
    }
}

var setTheme = function (theme) {
    document.getElementsByTagName('html')[0].setAttribute('class', theme);
    document.getElementsByTagName('html')[0].setAttribute('data-theme', theme);
}


toggleTheme(localStorage.getItem(THEME_KEY) !='dark');
